<?php 
namespace app\admin\controller;
use app\admin\controller\Base;
use think\Request;
use think\Session;
use think\Config;
use app\admin\model\Student as StudentM;
use think\Db;
use think\File;

class Logsystem extends Base
{
    //展示
    
	public  function index()
	{
        $id = input('get.id');
        
        $zxlog=db("zxlog")->where('res_id',$id)->order('z.create_time desc')
        ->alias('z')
        ->join('admin a', 'z.operator = a.id')
        ->field('z.*,a.username')
        ->select(); //咨询日志
        
       
        $zylog = db('zylog')->where('res_id',$id)->order('z.create_time desc')
        ->alias('z')
        ->join('admin a', 'z.operator = a.id')
        ->field('z.*,a.username')
        ->select();  //转移日志
      
        $tpl_param = array(
            'zxlog'  => $zxlog,
            'zylog'  => $zylog
        );
        $this->assign($tpl_param);
        return  $this->fetch();

    }

     //添加咨询日志
     public function addzxlog(){

        $resid = input('post.resid');
        $logtext = input('post.logtext');
        $user = $this->user_info();
        $re = db('zxlog')->insert([
            'res_id'=>$resid,
            'content'=>$logtext,
            'operator'=> $user['id'],
            'create_time' => time(),
            'update_time' => time(),
        ]);
        
        if($re){
            $re = db('student')->where('sid',$resid)->update(['zxlast_time'=>time()]);//最后咨询时间 更新
            if($re){
                $this->success('添加成功');
            }else{
                $this->success('数据更新失败');
            }
        }else{
            $this->success('添加失败');
        }

    }

   
}

 ?>